package com.ktgj.customer.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ktgj.common.core.annotation.Excel;
import com.ktgj.customer.domain.vo.ScheduleDetailsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktgj.customer.mapper.TravelItineraryMapper;
import com.ktgj.customer.domain.TravelItinerary;
import com.ktgj.customer.service.ITravelItineraryService;

/**
 * 旅游行程Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-11-10
 */
@Service
public class TravelItineraryServiceImpl implements ITravelItineraryService 
{
    @Autowired
    private TravelItineraryMapper travelItineraryMapper;

    /**
     * 查询旅游行程
     * 
     * @param travelItineraryId 旅游行程ID
     * @return 旅游行程
     */
    @Override
    public TravelItinerary selectTravelItineraryById(Long travelItineraryId)
    {
        return travelItineraryMapper.selectTravelItineraryById(travelItineraryId);
    }

    /**
     * 查询旅游行程列表
     * 
     * @param travelItinerary 旅游行程
     * @return 旅游行程
     */
    @Override
    public List<TravelItinerary> selectTravelItineraryList(TravelItinerary travelItinerary)
    {
        return travelItineraryMapper.selectTravelItineraryList(travelItinerary);
    }

    /**
     * 新增旅游行程
     * 
     * @param travelItinerary 旅游行程
     * @return 结果
     */
    @Override
    public int insertTravelItinerary(TravelItinerary travelItinerary)
    {
        return travelItineraryMapper.insertTravelItinerary(travelItinerary);
    }

    /**
     * 修改旅游行程
     * 
     * @param travelItinerary 旅游行程
     * @return 结果
     */
    @Override
    public int updateTravelItinerary(TravelItinerary travelItinerary)
    {
        return travelItineraryMapper.updateTravelItinerary(travelItinerary);
    }

    /**
     * 批量删除旅游行程
     * 
     * @param travelItineraryIds 需要删除的旅游行程ID
     * @return 结果
     */
    @Override
    public int deleteTravelItineraryByIds(Long[] travelItineraryIds)
    {
        return travelItineraryMapper.deleteTravelItineraryByIds(travelItineraryIds);
    }

    /**
     * 删除旅游行程信息
     * 
     * @param travelItineraryId 旅游行程ID
     * @return 结果
     */
    @Override
    public int deleteTravelItineraryById(Long travelItineraryId)
    {
        return travelItineraryMapper.deleteTravelItineraryById(travelItineraryId);
    }

    /**
     * 查询指定旅游产品行程安排
     * */
    @Override
    public List<ScheduleDetailsVo> scheduleDetailsVoList(Long groupId) throws Exception {
        if (groupId != null && groupId != 0){
            List<TravelItinerary> travelItineraries = travelItineraryMapper.selectTravelItinerary(groupId);
            if (travelItineraries != null && travelItineraries.size() > 0){
                List<ScheduleDetailsVo> scheduleDetailsVos = new ArrayList<>();
                for (int i = 0 ; i < travelItineraries.size() ; i++) {
                    ScheduleDetailsVo scheduleDetailsVo = new ScheduleDetailsVo();
                    scheduleDetailsVo.setTravelItineraryId(travelItineraries.get(i).getTravelItineraryId());
                    scheduleDetailsVo.setDay("第" + (i + 1) + "天");
                    scheduleDetailsVo.setTravelItineraryName(travelItineraries.get(i).getTravelItineraryName());
                    scheduleDetailsVos.add(scheduleDetailsVo);
                }
                return scheduleDetailsVos;
            }
            else {
                throw new Exception("未查到数据");
            }
        }
        else {
            throw new Exception("缺少必要参数");
        }
    }
}
